﻿using DevExpress.Mvvm.Gantt;
using System.Collections.ObjectModel;
using System.Windows;

namespace DevWpfApp.ResourceManage
{
    /// <summary>
    /// ResourceManageWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ResourceManageWindow : Window
    {
        public ResourceManageWindow()
        {
            InitializeComponent();
        }

        ObservableCollection<GanttResource> _gr = null;
        public ObservableCollection<GanttResource> GanttResources
        {
            set { this.DataContext = value; _gr = value; }
        }
        private void DelBtn_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid.SelectedItem == null)
                return;
            if (MessageBox.Show("确认删除吗？删除前请确保没有引用过该资源。", "确认", MessageBoxButton.YesNo, MessageBoxImage.Stop, MessageBoxResult.No) == MessageBoxResult.No)
                return;
            _gr.Remove(dataGrid.SelectedItem as GanttResource);
        }

        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            InputWindow win = new InputWindow();
            win.Title = "添加资源";
            win.DataName = "资源名称";
            if (win.ShowDialog() == true)
            {
                GanttResource resource = new GanttResource() { Id = ResourceIdGenerator.NewId(), Name = win.DataValue };
                _gr.Add(resource);
            }
        }
        public GanttResource SelectedResource { get; set; }
        private void ShowResourceBtn_Click(object sender, RoutedEventArgs e)
        {
            this.SelectedResource = dataGrid.SelectedItem as GanttResource;
            Close();
        }
    }
}
